#include "StdAfx.h"
#include "Algorytm.h"

/*Algorytm::Algorytm(void)
{
}

Algorytm::~Algorytm(void)
{
}*/

vector<vector<Wielomian>> AlgorytmNevillea(vector<Punkt> Wezly)
{
        Wielomian rezultat;

        vector<vector<Wielomian> > P ( Wezly.size(), vector<Wielomian>(Wezly.size()));

        for(int i = 0; i < Wezly.size(); i++)
        {
                //cout << "(" << i << ", " << i  << " ), ";
                P[i][i] = Wezly[i].y;
        }
        //cout << endl;

        for(int j = 1; j < Wezly.size(); j++)
        {
                for(int i = 0; i < Wezly.size() - j; i++)
                {
                        //cout << "(" << i << ", " << i + j  << " ), ";
                        P[i][i + j] = (Wielomian(-1, Wezly[i + j].x) * P[i][i + j - 1] + Wielomian(1, -Wezly[i].x) * P[i + 1][i + j]) / (Wezly[i + j].x - Wezly[i].x);
                }
                //cout << endl;
        }

        return P;
}
